package com.hunt.testspringboot;

import com.hunt.testspringboot.bean.Book;
import com.hunt.testspringboot.bean.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.Banner;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
public class TestspringbootApplication {

    @Value("${user.username}")
    private String name;

    @Value(value = "${user.age}")
    private String age;

    @Autowired
    private Student stu;

    @Autowired
    private Book book;

    public static void main(String[] args) {
        //SpringApplication.run(TestspringbootApplication.class, args);
        SpringApplicationBuilder springApplicationBuilder = new SpringApplicationBuilder(TestspringbootApplication.class);
        springApplicationBuilder.bannerMode(Banner.Mode.CONSOLE);

        springApplicationBuilder.run(args);
    }

    @RequestMapping(value = "/",produces = "text/plain;charset=UTF-8")
    public String index(){
        return "学生姓名:  "+name+"   年龄："+age;
    }

    @RequestMapping(value = "stu",method = RequestMethod.GET)
    public String student(){
        return "学生姓名："+stu.getName()+"   学生年龄："+stu.getAge()+"   年纪："+stu.getGrade();
    }

    @RequestMapping("book")
    public String book(){
        return "送你一本："+book.getName()+"  现在只要"+book.getPrice();
    }
}
